/*
提名链接 ; https://leetcode.cn/problems/design-spreadsheet/description/
*/

//题解代码 : 
class Spreadsheet {
public:
    vector<vector<int>> a;
    int ROW;
    Spreadsheet(int rows) {
        a.resize(rows+1,vector<int>(26,0));
        ROW = rows;
    }
    
    void setCell(string cell, int value) {
        int n = cell.size();
        int col = cell[0]-'A';
        int row = stoi(cell.substr(1,n-1));
        a[row][col] = value;
    }
    
    void resetCell(string cell) {
        int n = cell.size();
        int col = cell[0]-'A';
        int row = stoi(cell.substr(1,n-1));
        a[row][col] = 0;
    }
    
    int getValue(string formula) {
        int j = 0;
        string op1,op2;
        int n = formula.size();
        for(j=0;j<n;++j){
            if(formula[j]=='+') break;
        }
        int num1 = 0, num2 = 0;
        op1 = formula.substr(1,j-1);
        op2 = formula.substr(j+1,n-j-1);
        //cout<<op1<<" "<<op2<<endl;
        if(isdigit(formula[1])) num1 = stoi(op1);
        else{
            n = op1.size();
            int col = op1[0]-'A';
            int row = stoi(op1.substr(1,n-1));
            if(row>ROW) num2 = 0;
            else 
                num1 = a[row][col];
        }

        if(isdigit(formula[j+1])) num2 = stoi(op2);
        else{
            n = op2.size();
            int col = op2[0]-'A';
            int row = stoi(op2.substr(1,op2.size()-1));
            if(row>ROW) num2 = 0;
            else 
                num2 = a[row][col];
        }
        return num1 + num2;
    }
};
